<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>周纪实-员工列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="static/css/font.css">
<link rel="stylesheet" href="static/css/xadmin.css">
<script type="text/javascript" src="static/js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="static/lib/layui/layui.js"></script>
<script type="text/javascript" src="static/js/xadmin.js"></script>
<style type="text/css">
.laytable-cell-1-eAccount{
	width:200px;
}


</style>
</head>

<body class="layui-anim layui-anim-up">

	<div class="x-nav">
		<span class="layui-breadcrumb"> <a>周纪实管理</a> <a> <cite>周纪实审核</cite></a>
		</span> <a class="layui-btn layui-btn-small"
			style="line-height: 1.6em; margin-top: 3px; float: right"
			href="javascript:location.replace(location.href);" title="刷新"> <i
			class="layui-icon" style="line-height: 30px">ဂ</i></a>
	</div>
	<div class="x-body" id="container">
		<div class="layui-row">
			<div class="demoTable layui-col-md10 layui-form">

				员工工号：
				<div class="layui-inline">
					<input class="layui-input" name="account" id="eAccount"
						autocomplete="off">
				</div>
				<!--
				&nbsp&nbsp&nbsp 员工姓名：
				<div class="layui-inline">
					<input class="layui-input" name="name" id="eName"
						autocomplete="off">
				</div>
				-->
				&nbsp&nbsp&nbsp
				<button class="layui-btn" data-type="reload">搜索</button>
				&nbsp&nbsp&nbsp
				<button id="printSelectAdmin" type="button" class="layui-btn layui-btn-normal">打印</button>
			</div>


		</div>
		<!--demoTable-->
	</div>

	<div style="text-align: center">
		<table class="layui-table"
			lay-data="{height: 'full-150', cellMinWidth:80, url:'employeeWeekCheck/findSelective.do', page:true, id:'idTest'}"
			lay-filter="demo">
			<thead>
			<tr>
				<th lay-data="{type:'checkbox', fixed: 'left'}"></th>
				<th
						lay-data="{field:'eAccount',templet: '<span>{{d.employee.eAccount}}</span>', width:120, fixed: true,align: 'center'}">
					工号</th>
				<th
						lay-data="{field:'eName', templet: '<span>{{d.employee.eName}}</span>',width:120,align: 'center'}">
					姓名</th>

				<th
						lay-data="{field:'ePhone', templet: '<span>{{d.employee.ePhone}}</span>',width:120,align: 'center'}">
					电话</th>

				<th
						lay-data="{field:'pName', templet: '<span>{{d.position.pName}}</span>',minWidth:110,align: 'center'}">
					岗位</th>
				<th
						lay-data="{field:'dName', templet: '<span>{{d.department.dName}}</span>',minWidth:110,align: 'center'}">
					归属部门</th>
				<!--style="color:#008B8B;"-->
				<th
						lay-data="{field:'xCheckState',
						templet : function(d) {
							if(d.weekrment == null || d.weekrment == 'null'){
								return '未审核';
							}else{
								if(d.weekrment.xCheckState=='1' || d.weekrment.xCheckState=='2'){
					            	return '<strong>已审核</strong>';
								}else {
									return '未审核';
								}
							}
					    }
						,minWidth:110,align: 'center'}">
					审核状态</th>

				<th
						lay-data="{field:'xCheckScore',

						templet : function(d) {
							if(d.weekrment == null || d.weekrment == 'null'){
								return '0';
							}else{
								return d.weekrment.xCheckScore;
							}
					    }


						,minWidth:110,align: 'center'}">
					总分</th>

				<th
						lay-data="{fixed: 'right', width:160, align:'center', toolbar: '#barDemo'}"></th>
			</tr>
			</thead>
		</table>
	</div>

	</div>
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="check">审核</a>
		<!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
	</script>
	<script>

    window.onload = function () {
        //加载部门下拉搜索框
        var dId = $("#dId");
        $.ajax({
            url: 'department/findSelective.do?page=1&limit=999', //分页限制为999条，就是全部
            dataType: 'json',
            type: 'post',
            success: function (result) {
                // console.log(result.data);
                $.each(result.data, function (index, item) {
                    // console.log(index + "&" + item.dId);
                    dId.append("<option value=" + item.dId + ">" + item.dName + "</option>");// 下拉菜单里添加元素
                })
                layui.form.render('select');  //渲染select

            }
        });

    }


    // 刷新(主要用于批量删除，不能直接在里面刷新，那样会使操作失败，要跳出来执行)
    function myReload() {
        location.replace(location.href);
    }

    /* 监听打印选中行按钮 */
    $('#printSelectAdmin').click(function() {
        layui.use(['table', 'layer'], function() {
            var table = layui.table,
                layer = layui.layer;

            var checkStatus = table.checkStatus('idTest')
            // 判断是否选中数据
            if (checkStatus.data.length === 0) {
                layer.msg('请选中要打印分数的人员数据,再点击打印', {
                    icon: 2
                })
            } else {
                printSelect(checkStatus.data)
            }
        })
    })

    function getPreMonth(date) {
        var arr = date.split('-');
        var month = arr[1]; //获取当前日期的月份
        var month2 = parseInt(month) - 1;
        return month2;

        var Last_month = new Date().getMonth();
        Last_month = ((Last_month == 0) ? (12) : (Last_month));
    }

    /*
     * [自定义打印选中行数据]
     * @param  {[type]}  allData [传入选中行]
     */
    function printSelect(allData) {

        console.log("allDataAAAAA="+JSON.stringify(allData));
        //用于包含内容
        var v = document.createElement("div");
        //页面头部，导入css  ，media="print"表示打印时使用该样式
        var f = ["<head>", "<style>", "div{font-size:16px;}", ".main{width:100%;height:100%}",
            ".main div{width:300px;margin-right: 50px;display:inline-block;}", "</style>", "</head>"
        ].join("");
        var templateB = "";
        var contentHtml = "";

        var last_month = new Date().getMonth();
        last_month = ((last_month == 0) ? (12) : (last_month));

        var templateA =
			"<div style='width:700px ;height: 700px;'>" +
			"<table width='100%' style='text-align: center'>" +
			"<tr>" +
			"<td colspan='7' style='font-size: 30px'><strong>公务员平时考核月小结打分表</strong><br>" +
			"</td>" +
			"</tr>" +

			"<tr>" +
			"<td colspan='7' style='font-size: 25px'><strong>( "+last_month+"月份 )</strong><br>" +
			"</td>" +
			"</tr>" +

			"</table>" +
            "<table width='100%' style='text-align: left;' border='1'>" +
            "<tr style='text-align: center;'>" +
            "<td colspan='1' width='15%' height='50px;' style='font-size: 21px'><strong>员工姓名</strong></th>" +
            "<td colspan='6' width='25%' height='50px;' style='font-size: 21px'><strong>领导评分</strong></td>" +
            "</tr>"

        	for (let i = 0; i < allData.length; i++) {
				var data = allData[i]
				var xCheckScore='';
				if(data.weekrment == null){
                    xCheckScore = '0';
				}else{
                    xCheckScore = data.weekrment.xCheckScore;
				}
				var template =
					"<tr style='text-align: center;'>" +
					"<td colspan='1' width='15%' height='50px;' style='font-size: 21px'><strong>"+data.employee.eName+"</strong></th>" +
					"<td colspan='6' width='25%' height='50px;' style='font-size: 21px'><strong>"+xCheckScore+"</strong></td>" +
					"</tr>"
				templateB += template;
			}

        var templateC =
			/**  领导打分  **/
			"<tr>" +
			"<td colspan='7' width='100%' height='80px;' style='text-align: left;font-size: 33px'><strong>确认签字:</strong></td>" +
			"</tr>" +

			"<tr></tr>" +
			"</table>" +
			"</div>"

        contentHtml = templateA+templateB+templateC;

        //contentHtml为已拼凑好的内容
        $(v).append(contentHtml)
        //新建窗口
        var h = window.open("打印窗口", "_blank");
        //写入拼凑内容
        h.document.write(f + $(v).prop("outerHTML"));
        //调用打印
        h.print();
        //关闭页面
        h.close();
    }

    layui.use(['form', 'layedit', 'laydate', 'table'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , table = layui.table;

        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            }else if (obj.event === 'del') {
                layer.confirm('确定要删除吗', function (index) {
                    $.ajax({
                        type: 'post',
                        url: 'employee/deleteByPrimaryKey.do',
                        data: {"id": data.employee.eId},
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == 100) {
                                layer.msg('员工已删除!', {icon: 1, time: 4000});
                                obj.del();
                            }else{
                                layer.msg('删除失败!', {icon: 5, time: 1000});
                            }
                        },
                        error: function (data) {
                            layer.alert("抱歉！出现未知错误！", {icon: 5});
                        }

                    });
                    obj.del();
                    layer.close(index);
                    // location.reload();
                });
            }else if (obj.event === 'check') {
                layer.confirm('每月1-5号考评上月员工周纪实，是否了解', function (index) {
                    layer.open({
                        type: 2,
                        area: ['88%', '88%'],
                        fix: false, //不固定
                        maxmin: true,
                        shadeClose: true,
                        shade: 0.4,
                        title: '审核',
                        content: 'toPage.do?url=employee/week/employeeWeekCheck-score.html?eId='
                            + data.employee.eId
                            + '&dId=' + data.department.dId
                            + '&pId=' + data.position.pId
                            + '&eAccount=' + data.employee.eAccount
                    });
                    layer.close(index);
                });
            }
        });

        var $ = layui.$, active = {

            reload: function () {
                var eAccount = $('#eAccount');
                var eName = $('#eName');
                var dId = $('#dId');
             
                table.reload('idTest', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        e_account: eAccount.val(),
                        e_name: eName.val(),
                        d_id: dId.val()
                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        function relo() {
            var eAccount = $('#eAccount');
            var eName = $('#eName');
            var dId = $('#dId');
        
            // 执行重载
            table.reload('idTest', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    e_account: eAccount.val(),
                    e_name: eName.val(),
                    d_id: dId.val()
                }
            });
        }
    });

</script>

</body>

</html>
